﻿@{
    ViewBag.Title = "个人中心";
    Layout = "~/Views/Shared/_UserCenter.cshtml";
}
<link href="~/Content/css/index.css" rel="stylesheet" />
<link href="~/Content/css/ziy.css" rel="stylesheet" />
<script src="~/Content/js/jquery-1.4.4.min.js"></script>
<script src="~/Content/js/jquery.reveal.js"></script>
<script src="~/Content/js/chengs/jquery.js"></script>
<script src="~/Content/js/chengs/bootstrap.js"></script>
<script src="~/Content/js/chengs/city-picker.data.js"></script>
<script src="~/Content/js/chengs/city-picker.js"></script>
<script src="~/Content/js/chengs/main.js"></script>


@model MvcShoppingMall.Model.wst_user_address

<div class="mod_main">
    <div class="jib_xinx_kuang">
        <div class="shand_piaot">收货地址</div>
        <div class="shouh_diz_beij">



            @foreach (MvcShoppingMall.Model.wst_user_address item in ViewBag.address)
{
    <div class="shouh_diz_kuang shouh_diz_kuang_mor">
        <div class="item">
            <span class="labal">收件人：</span>
            <p>@item.userName</p>
        </div>
        <div class="item">
            <span class="labal">收货地址：</span>
            <p>@item.userAddress</p>
        </div>
        <div class="item">
            <span class="labal">手机：</span>
            <p>@item.userPhone</p>
        </div>
        <div class="item">
            <span class="labal">固定电话：</span>
            <p>0755-800820880</p>
        </div>
        @*<div class="item">
                <span class="labal">电子邮箱：</span>
                @*<p>@item.userEmail</p>
            </div>*@
        <div class="bianj_yv_shanc">
            <a href="#" class="mor_color">当前默认地址</a>

            @*EditAddress(@item.addressId)*@
            <a href="javascript:void(0)" onclick="" data-reveal-id="myModal_1">编辑</a>
            <a href="javascript:void(0)" onclick="del(@item.addressId)">删除</a>
        </div>
    </div>
}


            <div class="xinz_shouh_dz_ann"><a href="#" data-reveal-id="myModal">新增收货地址</a></div>
        </div>
    </div>
</div>
<!--新增地址表单-->
@using (Html.BeginForm("Add", "User", FormMethod.Post))
{
    <div id="myModal" class="reveal-modal">
        <div class="xint_biaot">
            <h3>新添收货地址</h3>
        </div>
        <div class="shouj_diz_b">
            <div class="biaod_1">
                <p><em>*</em>联系人：</p>
                <input type="text" class="text" name="userName" id="userName" />

            </div>

            <div class="biaod_1">
                <p><em>*</em>收货地址：</p>
                <input type="text" class="text text1" name="userAddress" id="userAddress" />
            </div>
            <div class="biaod_1 biaod_2">
                <div class="liangp_e">
                    <p><em>*</em>手机号码：</p>
                    <input type="text" class="text" name="userPhone" id="userPhone" />
                </div>
                @*<span class="huo_z">或</span>
                    <div class="liangp_e">
                        <p>固定电话：</p>
                        <input type="text" class="text" )"="">
                    </div>*@
            </div>
            @*<div class="biaod_1">
                    <p>邮箱：</p>
                    <input type="text" class="text text1" )"="">
                </div>*@
            <div class="biaod_1">
                <input class="diz_baoc" type="submit" value="保存">

            </div>
        </div>
        <a class="close-reveal-modal">×</a>
    </div>
}



<!--修改地址表单-->
@*@using (Ajax.BeginForm("Edit", "User", new AjaxOptions { HttpMethod = "post", OnSuccess = "success" }))
    {*@
<div id="myModal_1" class="reveal-modal">
    <div class="xint_biaot">
        <h3>修改收货地址</h3>
    </div>
    <div class="shouj_diz_b">
        <div class="biaod_1">
            <p><em>*</em>联系人：</p>
            <input id="userNames" type="text" class="text" value="" />
            @*@Html.TextBoxFor(u => u.userName, new { @class = "text" })*@
        </div>
        <div class="biaod_1">
            <p><em>*</em>收货地址：</p>
            <input id="userAddresss" type="text" class="text text1" value="" />
            @*@Html.TextBoxFor(u => u.userAddress, new { @class = "text text1" })*@
        </div>
        <div class="biaod_1 biaod_2">
            <div class="liangp_e">
                <p><em>*</em>手机号码：</p>
                <input id="userPhones" type="text" class="text" value="" />
                @*@Html.TextBoxFor(u => u.userPhone, new { @class = "text" })*@
            </div>
        </div>

        <div class="biaod_1">
            <input class="diz_baoc" type="button" value="保存" onclick="saveUpdateRegionConfig(1)">
        </div>
    </div>
    <a class="close-reveal-modal">×</a>
</div>
@*}*@


<script src="~/Scripts/jquery-1.8.2.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script type="text/javascript">


    ////修改地址
    //function EditAddress(id) {

    //}

    //修改地址
    function updateDistrict(id) {
        if (id != "" && id != null) {
            $.ajax({
                url: '/User/updateDistrict',
                type: 'post',
                data: { "id": id },
                datatype: 'json',
                async: false,
                success: function (_data) {
                    $("#userNames").prop("value", _data.userName);
                    $("#userAddress").prop("value", _data.userAddress);
                    $("#userPhone").prop("value", _data.userPhone);
                },
                error: function () {
                    alert("操作失败！");
                }
            });
        }
    }




    function saveUpdateRegionConfig(item) {
        //新增
        //if (item == 0) {
        //    var userName = $("#userName").val();
        //    var userAddress = $("#userAddress").val();
        //    var userPhone = $("#userPhone").val();

        //    if (userName == "") {
        //        alert("联系人不能为空");
        //    }

        //    if (userAddress == "") {
        //        alert("收货地址不能为空");
        //    }

        //    if (userPhone == "") {
        //        alert("联系电话不能为空");
        //    }

        //    $.ajax({
        //        url: '/User/addDistrict',
        //        type: 'post',
        //        data: { userName: userName, userAddress: userAddress, userPhone: userPhone },
        //        datatype: 'json',
        //        asyns: false,
        //        success: function (_data) {
        //            if (_data == true) {
        //                alert("添加成功");

        //                location.reload();
        //            }
        //        },
        //        error: function () {
        //            alert("添加失败");
        //        }
        //    });
        //}



        //编辑
        if (item == 1) {
            var userName = $("#userNames").val();
            var userAddress = $("#userAddresss").val();
            var userPhone = $("#userPhones").val();


            if (userName == "") {
                alert("联系人不能为空");
            }

            if (userAddress == "") {
                alert("收货地址不能为空");
            }

            if (userPhone == "") {
                alert("联系电话不能为空");
            }



            $.ajax({
                url: '/User/saveUpdateDistrict',
                type: 'post',
                data: { "userNames": userName, "userPhones": userPhone, "userAddresss": userAddress },
                datatype: 'json',
                async: false,
                success: function (_data) {
                    if (_data == true) {
                        alert("修改成功！");
                        location.reload();
                    }
                },
                error: function () {
                    alert("修改失败！");
                }
            });
        }


    }



    //删除地址
    function del(id) {
        if (confirm("是不是要删除啊?")) {
            $.post("/User/Delete/" + id, null,
                function success(data) {
                    if (data == "ok") {
                        alert("删除成功");
                        window.location.href = "/User/Destination";
                    }
                    else {
                        alert("删除失败");
                    }
                })
        }

    }
</script>



